﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using MyFloridaHouse.DataAccess.Extensions;
using MyFloridaHouse.libSvDTO;

namespace MyFloridaHouse.DataAccess
{
    public partial class DAL_CensusData
    {

        /// <summary>
        /// Gets the regions data in view.
        /// </summary>
        /// <param name="iTargetLayerID">The itargetlayerID.</param>
        /// <param name="iRegionIDList">The iregionID list.</param>
        /// <param name="iSourceLayerID">The isourcelayerID.</param>
        /// <param name="iDictionaryIDList">The idictionaryID list.</param>
        /// <returns>List of <see cref="RegionDataDTO"/></returns>
        /// <remarks>SPROC: usp_GetRegionsDataInView</remarks>
        public List<RegionDataDTO> GetRegionListData(int iTargetLayerID, List<int> regionIDList, string iSourceLayerIDList, string iDictionaryIDList)
        {
            List<RegionDataDTO> itemList = new List<RegionDataDTO>();

            string iRegionIDList = string.Join(",", regionIDList);

            string storedProcedureName = "usp_tl10GetRegionsDataInView10";

            using (SqlConnection db = Connect())
            {
                SqlCommand StoredProcedureCommand = new SqlCommand(storedProcedureName, db);
                StoredProcedureCommand.CommandType = CommandType.StoredProcedure;
                SqlParameter dataPartIDParm = StoredProcedureCommand.Parameters.AddWithValue("iTargetLayerID", iTargetLayerID);
                dataPartIDParm.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm2 = StoredProcedureCommand.Parameters.AddWithValue("iRegionIDList", iRegionIDList);
                dataPartIDParm2.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm3 = StoredProcedureCommand.Parameters.AddWithValue("iSourceLayerIDList", iSourceLayerIDList);
                dataPartIDParm3.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm4 = StoredProcedureCommand.Parameters.AddWithValue("iDictionaryIDList", iDictionaryIDList);
                dataPartIDParm4.Direction = ParameterDirection.Input;

                db.Open();
                using (SqlDataReader rdr = StoredProcedureCommand.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        itemList.Add(RegionDataDTODataContract.DataContract(rdr));
                    }
                }
            }


            return itemList;
        }

    }
}
